package model.dao;

import java.util.HashMap;
import java.util.List;

import vo.InventoryVO;

import com.ibatis.sqlmap.client.SqlMapClient;

public class InventoryDAO {

	private SqlMapClient client;
	
	private static InventoryDAO dao=new InventoryDAO();
	
	private InventoryDAO(){
		SqlMapFactory factory = SqlMapFactory.getInstance();
		client = factory.getClient();
	}
	
	public static InventoryDAO getinstance(){
		if(dao==null) dao=new InventoryDAO();
		return dao;
	}
	
	public List selectAllInventory(int pageNo, String id, String searchDate, String searchProduct) throws Exception{
		
		HashMap map = new HashMap();			
		map.put("page", pageNo);
		map.put("searchId", id);
		map.put("searchDate",searchDate);
		map.put("searchProduct", searchProduct);
		List list=client.queryForList("inventory.selectAllInventory", map);			
		return list;
	}
	
	public int selectAllCount(String id, String searchDate, String searchProduct) throws Exception{
		HashMap map = new HashMap();				
		map.put("searchId", id);
		map.put("searchDate",searchDate);
		map.put("searchProduct", searchProduct);
		int count=(Integer) client.queryForObject("inventory.selectAllCount",map);		
		return count;
	}
	
	public InventoryVO selectInventoryDetailOfStock(String id, String stockNo) throws Exception{
			
		HashMap map = new HashMap();			
		map.put("searchId", id);
		map.put("stockNo", stockNo);
		InventoryVO ivo=(InventoryVO) client.queryForObject("inventory.selectInventoryDetailOfStock",map);
		return ivo;		
	}
	
	public List selectInventoryDetailOfSale(String id, String stockNo) throws Exception {
		
		HashMap map = new HashMap();			
		map.put("searchId", id);
		map.put("stockNo", stockNo);		
		List list=(List) client.queryForList("inventory.selectInventoryDetailOfSale", map);		
		return list;		
	}
	
	public List selectBestItemList(String id)throws Exception{		
		List list=client.queryForList("inventory.selectBestItemList",id);
		return list;
	}
}
